<template>
    <div>
        <p>1、默认获取所有图书信息</p>
        <button @click="getAllFn">神奇按钮-查看控制台</button>

        <p>3. 新增图书信息</p>
        <input type="text" placeholder="书名" v-model="bookObj.bokname">
        <input type="text" placeholder="作者" v-model="bookObj.author">
        <input type="text" placeholder="出版社" v-model="bookObj.publisher">
        <button @click="sendFn">发布按钮</button>
    </div>
</template>
<script>
import axios from "axios";
// import { log } from "util";
export default {
  data() {
    return {
      bName: "",
      bookObj: {
        bookname: "",
        author: "",
        publisher: ""
      }
    };
  },
  methods: {
    getAllFn() {
      axios({
        url: "http://123.57.109.30:3006/api/getbooks",
        method: "GET"
      }).then(res => {
        console.log(res);
      });
    },
    sendFn() {
      axios({
        url: "http://123.57.109.30:3006/api/addbook",
        method: "POST",
        data: {
          appkey: "7250d3eb-18e1-41bc-8bb2-11483665535a",
          ...this.bookObj
          // 等同于下面
          // bookname: this.bookObj.bookname,
          // author: this.bookObj.author,
          // publisher: this.bookObj.publisher
        }
      });
    }
  }
};
</script>
<style>
</style>


